package com.wnhz.work.jy.adapter;

/**
 * Created by Administrator on 2016/10/17 0017.
 */

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.HomeFragment1.RecommendBean;
import com.wnhz.work.jy.bean.OrderHasBean;

import org.xutils.x;

import java.util.List;

/**
 * ---订单生成适配器
 */
public class OrderHasAdapter extends BaseAdapter {
    private Context context;
    private List<RecommendBean> orderList;
    private View.OnClickListener listener;

    public OrderHasAdapter(Context context, List<RecommendBean> orderList, View.OnClickListener listener) {
        this.context = context;
        this.orderList = orderList;
        this.listener = listener;

    }

    @Override
    public int getCount() {
        return orderList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        OrderHasViewHolder viewHolder = new OrderHasViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.order_has_item, null);
            viewHolder.iv_delete = (ImageView) convertView.findViewById(R.id.iv_delete);
            viewHolder.iv_goods = (ImageView) convertView.findViewById(R.id.iv_goods);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            viewHolder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
            viewHolder.tv_minus = (ImageView) convertView.findViewById(R.id.tv_minus);
            viewHolder.tv_add = (ImageView) convertView.findViewById(R.id.tv_add);
            viewHolder.tv_shopping_number = (TextView) convertView.findViewById(R.id.tv_shopping_number);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (OrderHasViewHolder) convertView.getTag();
        }
//        ImageLoader.getInstance().displayImage(orderList.get(position).getImage(), viewHolder.iv_goods);
        x.image().bind(viewHolder.iv_goods,orderList.get(position).getGoodImg());
        viewHolder.tv_name.setText(orderList.get(position).getGoodName());
        viewHolder.tv_price.setText("¥ " + orderList.get(position).getGoodPrice());

        viewHolder.tv_shopping_number.setText(orderList.get(position).getmYNum()+"");

        viewHolder.iv_delete.setOnClickListener(listener);
        viewHolder.iv_delete.setTag(position);
        viewHolder.tv_minus.setOnClickListener(listener);
        viewHolder.tv_minus.setTag(position);
        viewHolder.tv_add.setOnClickListener(listener);
        viewHolder.tv_add.setTag(position);

        return convertView;
    }

    class OrderHasViewHolder {
        ImageView iv_delete;
        ImageView iv_goods;
        TextView tv_name;
        TextView tv_price;
        ImageView tv_minus;
        ImageView tv_add;
        TextView tv_shopping_number;
    }
}
